package com.wyl.servlet

import com.wyl.pojo.Person
import javax.servlet.annotation.WebServlet
import javax.servlet.http.HttpServlet
import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse

/**
 * session获取值
 */
@WebServlet("/session02")
class SessionServlet02 : HttpServlet() {
    override fun doPost(req: HttpServletRequest, resp: HttpServletResponse) {
        req.characterEncoding = "utf-8"
        resp.contentType = "text/html;charset=UTF-8"

        resp.writer.use { out ->
            req.session.apply {
                val name = getAttribute("name") as String
                val person = getAttribute("person") as Person
                out.println(name)
                out.println(person)
            }
        }
    }

    override fun doGet(req: HttpServletRequest, resp: HttpServletResponse) {
        doPost(req, resp)
    }
}